
package com.salt.common.utils;

import org.apache.commons.lang3.time.DateFormatUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;


public class DateUtil extends org.apache.commons.lang3.time.DateUtils {

	private static String[] parsePatterns = {
		"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
		"yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
		"yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"};

	/**
	 * 得到当前日期字符串 格式（yyyy-MM-dd）
	 */
	public static String getDate() {
		return getDate("yyyy-MM-dd");
	}

	/**
	 * 得到当前日期字符串 格式（yyyy-MM-dd） pattern可以为："yyyy-MM-dd" "HH:mm:ss" "E"
	 */
	public static String getDate(String pattern) {
		return DateFormatUtils.format(new Date(), pattern);
	}

	/**
	 * 得到日期字符串 默认格式（yyyy-MM-dd） pattern可以为："yyyy-MM-dd" "HH:mm:ss" "E"
	 */
	public static String formatDate(Date date, Object... pattern) {
		String formatDate = null;
		if (pattern != null && pattern.length > 0) {
			formatDate = DateFormatUtils.format(date, pattern[0].toString());
		} else {
			formatDate = DateFormatUtils.format(date, "yyyy-MM-dd");
		}
		return formatDate;
	}

	/**
	 * 得到日期时间字符串，转换格式（yyyy-MM-dd HH:mm:ss）
	 */
	public static String formatDateTime(Date date) {
		return formatDate(date, "yyyy-MM-dd HH:mm:ss");
	}

	/**
	 * 得到当前时间字符串 格式（HH:mm:ss）
	 */
	public static String getTime() {
		return formatDate(new Date(), "HH:mm:ss");
	}
	/**
	 * 得到当前日期和时间字符串 格式（yyyy-MM-dd HH:mm:ss）
	 */
	public static String getDateTime() {
		return formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");
	}

	/**
	 * 得到当前年份字符串 格式（yyyy）
	 */
	public static String getYear(Date d) {
		return formatDate(d, "yyyy");
	}

	/**
	 * 得到当前月份字符串 格式（MM）
	 */
	public static String getMonth(Date d) {
		return formatDate(d, "MM");
	}

	/**
	 * 得到当前月份字符串 格式（MM）
	 */
	public static String getWorkYear(Date d) {
		String y = formatDate(d, "yyyy");
		String m = formatDate(d, "MM");
		String dd = formatDate(d, "dd");
		if(m.equals("12") && Integer.valueOf(dd)>25){
			y = (Integer.valueOf(y)+1)+"";
		}
		return y;

	}

	/**
	 * 得到当前月份字符串 格式（MM）
	 */
	public static String getWorkMonth(Date d) {
		String m = formatDate(d, "MM");
		if(Integer.valueOf(DateUtil.formatDate(d, "dd")) > 25){
		 m = (Integer.valueOf(m)+1)+"";
		 if(m.equals("13")) m = "1";
		}
		return Integer.valueOf(m)+"";

	}

	/**
	 * 得到当天字符串 格式（dd）
	 */
	public static String getDay(Date d) {
		return formatDate(d, "dd");
	}

	/**
	 * 得到当前星期字符串 格式（E）星期几
	 */
	public static String getWeek(Date d) {
		return formatDate(d, "E");
	}

	/**
	 * 日期型字符串转化为日期 格式
	 * { "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm",
	 *   "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm",
	 *   "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm" }
	 */
	public static Date parseDate(Object str) {
		if (str == null){
			return null;
		}
		try {
			return parseDate(str.toString(), parsePatterns);
		} catch (ParseException e) {
			return null;
		}
	}

	/**
	 * 获取过去的天数
	 * @param date
	 * @return
	 */
	public static long pastDays(Date date) {
		long t = new Date().getTime()-date.getTime();
		return t/(24*60*60*1000);
	}

	/**
	 * 获取过去的小时
	 * @param date
	 * @return
	 */
	public static long pastHour(Date date) {
		long t = new Date().getTime()-date.getTime();
		return t/(60*60*1000);
	}

	/**
	 * 获取过去的分钟
	 * @param date
	 * @return
	 */
	public static long pastMinutes(Date date) {
		long t = new Date().getTime()-date.getTime();
		return t/(60*1000);
	}

	/**
	 * 转换为时间（天,时:分:秒.毫秒）
	 * @param timeMillis
	 * @return
	 */
    public static String formatDateTime(long timeMillis){
		long day = timeMillis/(24*60*60*1000);
		long hour = (timeMillis/(60*60*1000)-day*24);
		long min = ((timeMillis/(60*1000))-day*24*60-hour*60);
		long s = (timeMillis/1000-day*24*60*60-hour*60*60-min*60);
		long sss = (timeMillis-day*24*60*60*1000-hour*60*60*1000-min*60*1000-s*1000);
		return (day>0?day+",":"")+hour+":"+min+":"+s+"."+sss;
    }

	/**
	 * 获取两个日期之间的天数
	 *
	 * @param before
	 * @param after
	 * @return
	 */
	public static double getDistanceOfTwoDate(Date before, Date after) {
		long beforeTime = before.getTime();
		long afterTime = after.getTime();
		return (afterTime - beforeTime) / (1000 * 60 * 60 * 24);
	}

	/**
	 * 取上个月第一天
	 * @return
	 */
    public static Date getLastMonthFirstDay(){
    	Calendar cal = Calendar.getInstance();
    	cal.add(cal.MONTH,-1);//得到上个月的月份
    	cal.set(Calendar.DAY_OF_MONTH, 1);
    	Date d = cal.getTime();
    	return d;
    }

    /**
	 * 取上个月最后一天
	 * @return
	 */
    public static Date getLastMonthLastDay(){
    	Calendar cal = Calendar.getInstance();
    	cal.set(Calendar.DAY_OF_MONTH, 0);
    	Date d = cal.getTime();
    	return d;
    }


    /**
     * 得到月的总天数
     * @param date 日期
     * @return 指定日期当前月的总天数
     */
    public static int getMonthTotalDays(Date date){
    	Calendar aCalendar = Calendar.getInstance(Locale.CHINA);

    	aCalendar.setTime(date);
    	int day=aCalendar.getActualMaximum(Calendar.DATE);
    	return day;
    }

    /**
     * 得到年的总天数
     * @param date 日期
     * @return 指定日期当前年的总天数
     */
    public static int getYearTotalDays(Date date){
    	int year = Integer.parseInt(formatDate(date, "yyyy"));
    	if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0){
    		return 366;
    	}
    	return 365;
    }


//	1.Calendar 转化 String
	 //获取当前时间的具体情况,如年,月,日,week,date,分,秒等
	public static String convertCalToString(){
		Calendar calendar = Calendar.getInstance();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String dateStr = sdf.format(calendar.getTime());
		return dateStr;
	}

//	2.String 转化Calendar
	public static Calendar convertYYYYMMDDToCal(String str){
		SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
		Date date;
		try {
			date = sdf.parse(str);
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			return calendar;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return null;
	}

//	5.Date 转化Calendar
	public static Calendar convertDateToCal(Date date){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		return calendar;
	}

//	6.Calendar转化Date
	public static Date ConvertCalToDate(Calendar calendar){
		Date date =calendar.getTime();
		return date;
	}
	
	/**
	 * 取得用户当天上班时间
	 * @param cal
	 * @param dailyType
	 * @param dailyTime
	 * @return
	 */
	/*public static Date getDailyStartTime(Calendar cal, String dailyType, int dailyTime){
		//TODO 只考虑白班和夜班的情况
		if(Constants.DAILY_DAY.equals(dailyType)){
			cal.set(Calendar.HOUR_OF_DAY, 9);
		}else{
			cal.set(Calendar.HOUR_OF_DAY, 9+(24 - dailyTime));
		}
		
		return ConvertCalToDate(cal);
	}*/
	
	/**
	 * 取得用户当天上班时间
	 * @param cal
	 * @param dailyType
	 * @param dailyTime
	 * @return
	 */
//	public static Date getDailyEndTime(Calendar cal, String dailyType, int dailyTime){
//		//TODO 只考虑白班和夜班的情况
//		if(Constants.DAILY_NIGHT.equals(dailyType)){
//			cal.set(Calendar.HOUR_OF_DAY, 9);
//		}else{
//			cal.set(Calendar.HOUR_OF_DAY, 9+ dailyTime);
//		}
//		
//		return ConvertCalToDate(cal);
//	}

	/**
	 * 取上个月日期
	 * @param date yyyy-MM-dd
	 * @return yyyy-MM-dd
	 */
	public static String getLastMonth(String date){
		Calendar c = convertYYYYMMDDToCal(date);
		c.add(Calendar.MONTH, -1);
		return formatDate(ConvertCalToDate(c),"yyyy-MM-dd");
	}
	/**
	 * 取上周日期
	 * @param date yyyy-MM-dd
	 * @return yyyy-MM-dd
	 */
	public static String getLastWeek(String date){
		Calendar c = convertYYYYMMDDToCal(date);
		c.add(Calendar.WEEK_OF_YEAR, -1);
		return formatDate(ConvertCalToDate(c),"yyyy-MM-dd");
	}
	
	/**
	 * 取前一天
	 * @param date yyyy-MM-dd
	 * @return yyyy-MM-dd
	 */
	public static String getLastDay(String date){
		Calendar c = convertYYYYMMDDToCal(date);
		c.set(Calendar.DATE, c.get(Calendar.DATE) - 1);
		return formatDate(ConvertCalToDate(c),"yyyy-MM-dd");
	}
	/**
	 * 取后一天
	 * @param date yyyy-MM-dd
	 * @return yyyy-MM-dd
	 */
	public static String getNextDay(String date){
		Calendar c = convertYYYYMMDDToCal(date);
		c.set(Calendar.DATE, c.get(Calendar.DATE) + 1);
		return formatDate(ConvertCalToDate(c),"yyyy-MM-dd");
	}
	/**
	 * 取前n天
	 * @param date yyyy-MM-dd
	 * @return yyyy-MM-dd
	 */
	public static String getLastNDay(String date, int day){
		Calendar c = convertYYYYMMDDToCal(date);
		c.set(Calendar.DATE, c.get(Calendar.DATE) - day);
		return formatDate(ConvertCalToDate(c),"yyyy-MM-dd");
	}
	
	/**
	 * 取上个月日期
	 * @param date yyyy-MM-dd
	 * @return yyyy-MM-dd
	 */
	public static Date getLastMonth(Date date){
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		c.add(Calendar.MONTH, -1);
		return c.getTime();
	}
	
	/**
	 * 取前一天
	 * @param date yyyy-MM-dd
	 * @return yyyy-MM-dd
	 */
	public static Date getLastDay(Date date){
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		c.set(Calendar.DATE, c.get(Calendar.DATE) - 1);
		return c.getTime();
	}
	/**
	 * 取年的第一天
	 * @param date yyyy-MM-dd
	 * @return yyyy-MM-dd
	 */
	public static String getFirstDayOfYear(String date){
		Calendar c = convertYYYYMMDDToCal(date);
		c.set(c.get(Calendar.YEAR),0,1);
		return formatDate(ConvertCalToDate(c),"yyyy-MM-dd");
	}


	/**
	 * 取年的第一天
	 * @param date yyyy-MM-dd
	 * @return yyyy-MM-dd
	 */
	/*public static Date getFirstDayOfYear(Date date){
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		c.set(c.get(Calendar.YEAR),0,1);
		return c.getTime();
	}*/
	
	/**
	 * 取得今天是一年中的第几天
	 */
	public static int getWhichDayOfYear(){
		Date date=new Date();  
        Calendar ca=Calendar.getInstance();  
        ca.setTime(date);  
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日");  
          
        String st=sdf.format(date);  
        int i = ca.get(Calendar.DAY_OF_YEAR); 
        return i;
	}
	
    /** 
     * get first date of given month and year 
     * @param year 
     * @param month 
     * @return 
     */  
    public static String getFirstDayOfMonth(int year,int month){
        String monthStr = month < 10 ? "0" + month : String.valueOf(month);  
        return year + "-"+monthStr+"-" +"01";  
    }  
      
    /** 
     * get the last date of given month and year 
     * @param year 
     * @param month 
     * @return 
     */  
    public static String getLastDayOfMonth(int year,int month){  
        Calendar calendar = Calendar.getInstance();  
        calendar.set(Calendar.YEAR , year);  
        calendar.set(Calendar.MONTH , month - 1);  
        calendar.set(Calendar.DATE , 1);  
        calendar.add(Calendar.MONTH, 1);  
        calendar.add(Calendar.DAY_OF_YEAR , -1);
		int i = calendar.get(Calendar.MONTH) + 1;
		if (i < 10) {
			return calendar.get(Calendar.YEAR) + "-0" + (calendar.get(Calendar.MONTH) + 1) + "-" +
					calendar.get(Calendar.DAY_OF_MONTH);
		} else {
			return calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-" +
					calendar.get(Calendar.DAY_OF_MONTH);
		}

    }  
      
    /** 
     * get Calendar of given year 
     * @param year 
     * @return 
     */  
    public static Calendar getCalendarFormYear(int year){  
        Calendar cal = Calendar.getInstance();  
        cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);        
        cal.set(Calendar.YEAR, year);  
        return cal;  
    }  
      
    /** 
     * get start date of given week no of a year 
     * @param year 
     * @param weekNo 
     * @return 
     */  
    public static String getStartDayOfWeekNo(int year,int weekNo){  
        Calendar cal = getCalendarFormYear(year);  
        cal.set(Calendar.WEEK_OF_YEAR, weekNo);  
        int y = cal.get(Calendar.YEAR);
        int mon =  (cal.get(Calendar.MONTH) + 1);
        String month = mon +"";
        int day = cal.get(Calendar.DAY_OF_MONTH);
        String d = day +"";

        if(mon < 10) month = "0"+mon;
        if(day < 10) d = "0"+d;
        
        return y + "-" + month + "-" +  
               d;      
          
    }  
      
    /** 
     * get the end day of given week no of a year. 
     * @param year 
     * @param weekNo 
     * @return 
     */  
    public static  String getEndDayOfWeekNo(int year,int weekNo){  
        Calendar cal = getCalendarFormYear(year);  
        cal.set(Calendar.WEEK_OF_YEAR, weekNo);  
        cal.add(Calendar.DAY_OF_WEEK, 6);  
        return cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH) + 1) + "-" +  
               cal.get(Calendar.DAY_OF_MONTH);      
    }  
    
    /**
     * 获取当前日期是第几周
     * @return
     */
    public static int getWhichWeek(Date d){
    	
    	Calendar calendar = Calendar.getInstance();  
    	calendar.setFirstDayOfWeek(Calendar.MONDAY);  
    	calendar.setTime(d);  
    	  
    	int res = calendar.get(Calendar.WEEK_OF_YEAR);
    	return res;
    }

	/**
	 * 获取当前日期是第几周
	 * @return
	 */
	public static int getWhichWeek(String date){
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		Date d = parseDate(date);
		Calendar calendar = Calendar.getInstance();
		calendar.setFirstDayOfWeek(Calendar.MONDAY);
		calendar.setTime(d);

		int res = calendar.get(Calendar.WEEK_OF_YEAR);
		return res;
	}
    
    public static String getFirstDayOfMon(String date){
    	SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    	Date d = parseDate(date);
	    Calendar c = Calendar.getInstance();  
	    c.setTime(d);
	    c.add(Calendar.MONTH, 0);
	    c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天 
	    String first = format.format(c.getTime());
	    return first;
    }         
    public static String getLastDayOfMon(String date){
    	SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    	Date d = parseDate(date);
         //获取当前月最后一天
	     Calendar c = Calendar.getInstance();
	     c.setTime(d);
	     c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));  
         String last = format.format(c.getTime());
         return last;
    }
    
    /**
     * 取相差天数
     * @param fDate
     * @param oDate
     * @return
     */
    public static int daysOfTwo(Date fDate, Date oDate) {

        Calendar aCalendar = Calendar.getInstance();

        aCalendar.setTime(fDate);

        int day1 = aCalendar.get(Calendar.DAY_OF_YEAR);

        aCalendar.setTime(oDate);

        int day2 = aCalendar.get(Calendar.DAY_OF_YEAR);

        return day2 - day1;

     }
    
    /**
     * 取相差月数
     * @param fDate
     * @param oDate
     * @return
     */
    public static int monthsOfTwo(Date fDate, Date oDate) {
        Calendar aCalendar = Calendar.getInstance();
        aCalendar.setTime(fDate);
        int day1 = aCalendar.get(Calendar.MONTH);
        aCalendar.setTime(oDate);
        int day2 = aCalendar.get(Calendar.MONTH);
        return day2 - day1;
     }
    
    /**
     * 取相差周数
     * @param fDate
     * @param oDate
     * @return
     */
    public static int weeksOfTwo(Date fDate, Date oDate) {
        Calendar aCalendar = Calendar.getInstance();
        aCalendar.setTime(fDate);
        int day1 = aCalendar.get(Calendar.WEEK_OF_YEAR);
        aCalendar.setTime(oDate);
        int day2 = aCalendar.get(Calendar.WEEK_OF_YEAR);
        return day2 - day1;
     }

    /**
     * 取得月的第一个工作日
     * @param inputDate
     * @return
     */
  /*  public static String getMonthFirstWorkDay26(String inputDate){
    	SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    	Date d = parseDate(inputDate);
	    Calendar c = Calendar.getInstance();  
	    c.setTime(d);
	    Calendar monthFirstWorkDay = Calendar.getInstance();
	    monthFirstWorkDay.setTime(d);
	    monthFirstWorkDay.set(Calendar.DAY_OF_MONTH, Global.getFirstDayOfMonth());
	    if (c.compareTo(monthFirstWorkDay)<0){
	    	monthFirstWorkDay.add(Calendar.MONTH , -1);
	    }
	    return format.format(monthFirstWorkDay.getTime());
    }*/
    
    /**
     * 取得月的最后一个工作日
     * @param inputDate
     * @return
     */
   /* public static String getMonthLastWorkDay26(String inputDate){
    	SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    	String monthFirstWorkDate = getMonthFirstWorkDay26(inputDate);
    	monthFirstWorkDate = DateUtils.getLastNDay(monthFirstWorkDate, 1);
    	
    	Date d = parseDate(monthFirstWorkDate);
    	
	    Calendar c = Calendar.getInstance();  
	    c.setTime(d);
	    c.set(Calendar.MONTH, c.get(Calendar.MONTH)+1);
	    return format.format(c.getTime());
    }
*/
    /**
     * 取得年的第一个工作日
     * @param inputDate
     * @return
     */
    public static String getLastYearFirstWorkDay1226(String inputDate){
    	SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    	Date d = parseDate(inputDate);
    	
	    Calendar c = Calendar.getInstance();  
	    c.setTime(d);
	    Calendar yearFirstWorkDay = Calendar.getInstance();
	    yearFirstWorkDay.setTime(d);
	    yearFirstWorkDay.set(Calendar.MONTH, 11);
	    yearFirstWorkDay.set(Calendar.DAY_OF_MONTH, 26);
	    if (c.compareTo(yearFirstWorkDay)<0){
	    	yearFirstWorkDay.add(Calendar.YEAR , -1);
	    }
	    return format.format(yearFirstWorkDay.getTime());
    }

    
    /**
     * 取得周的第一个工作日
     * @param inputDate
     * @return
     */
    /*public static String getFirstWorkDayOfWeek(String inputDate){
    	SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    	Date d = parseDate(inputDate);
    	
	    Calendar c = Calendar.getInstance();  
	    c.setTime(d);
	    Calendar yearFirstWorkDay = Calendar.getInstance();
	    yearFirstWorkDay.setTime(d);
	    yearFirstWorkDay.set(Calendar.DAY_OF_WEEK, Global.getFirstDayOfWeek());
	    
	    return format.format(yearFirstWorkDay.getTime());
    }*/
    
    /**
     * 取得周的第一个工作日 ( 因为水和电是没周五统计)
     * @param inputDate
     * @return
     */
    public static String getFirstWorkDayOfWeekForFriday(String inputDate){
    	SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    	Date d = parseDate(inputDate);
    	
	    Calendar c = Calendar.getInstance();  
	    c.setTime(d);
	    Calendar yearFirstWorkDay = Calendar.getInstance();
	    yearFirstWorkDay.setTime(d);
	    yearFirstWorkDay.set(Calendar.DAY_OF_WEEK, 5);
	    
	    return format.format(yearFirstWorkDay.getTime());
    }
    /*
    
    *//**
     * 取得周的最后一个工作日
     * @param inputDate
     * @return
     *//*
    public static String getLastWorkDayOfWeek(String inputDate){
    	SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    	Date d = parseDate(inputDate);
    	
	    Calendar c = Calendar.getInstance();  
	    c.setTime(d);
	    Calendar yearFirstWorkDay = Calendar.getInstance();
	    yearFirstWorkDay.setTime(d);
	    yearFirstWorkDay.set(Calendar.DAY_OF_WEEK, Global.getFirstDayOfWeek()+6);
	    
	    return format.format(yearFirstWorkDay.getTime());
    }
    
    *//**
     * 取得周的最后一个星期五
     * @param inputDate
     * @return
     *//*
    public static String getLastFriDayOfWeek(String inputDate){
    	SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    	Date d = parseDate(inputDate);
    	
	    Calendar c = Calendar.getInstance();  
	    c.setTime(d);
	    Calendar yearFirstWorkDay = Calendar.getInstance();
	    yearFirstWorkDay.setTime(d);
	    yearFirstWorkDay.set(Calendar.DAY_OF_WEEK, Global.getFirstDayOfWeek()+5);
	    
	    return format.format(yearFirstWorkDay.getTime());
    }
    *//**
     * 根据周期类型（周）和时间范围取得所在范围的 统计周期列表
     * @param period
     * @param beginDate
     * @param endDate
     * @return
     *//*
    public static List<PeriodEntity> getDayPeriodList(String beginDate, String endDate){
    	List<PeriodEntity> periodList = Lists.newArrayList();
    	String periodBeginDate = beginDate;
    	String periodEndDate = "";
    	while (periodBeginDate.compareTo(endDate) <=0){
    		PeriodEntity entity = new PeriodEntity();
//    		periodEndDate = DateUtils.getLastNDay(periodBeginDate, -1);
    		if(periodEndDate.compareTo(endDate) >=0){
    			entity.setBeginDate(endDate);
//    			entity.setEndDate(endDate);
    			entity.setName(endDate);
    			periodList.add(entity);
    			break;
    		}else{
    			entity.setBeginDate(periodBeginDate);
//    			entity.setEndDate(periodEndDate);
    			entity.setName(periodEndDate);
    		}
    		periodList.add(entity);
    		periodBeginDate = DateUtils.getLastNDay(periodBeginDate, -1);
    		
    	}
    	
//    	for(PeriodEntity e: periodList){
//    		System.out.println(e.getBeginDate()+"-"+e.getEndDate());
//    	}
    	return periodList;
    }
    
    
    *//**
     * 根据周期类型（周）和时间范围取得所在范围的 统计周期列表
     * @param period
     * @param beginDate
     * @param endDate
     * @return
     *//*
    public static List<PeriodEntity> getWeekPeriodList(String beginDate, String endDate){
    	List<PeriodEntity> periodList = Lists.newArrayList();
    	String periodBeginDate = beginDate;
    	String periodEndDate = "";
    	while (periodBeginDate.compareTo(endDate) <=0){
    		PeriodEntity entity = new PeriodEntity();
    		periodEndDate = getLastWorkDayOfWeek(periodBeginDate);
    		if(periodEndDate.compareTo(endDate) >=0){
    			entity.setBeginDate(periodBeginDate);
    			entity.setEndDate(endDate);
    			entity.setName(endDate);
    			periodList.add(entity);
    			break;
    		}else{
    			entity.setBeginDate(periodBeginDate);
    			entity.setEndDate(periodEndDate);
    			entity.setName(periodEndDate);
    		}
    		periodList.add(entity);
    		periodBeginDate = DateUtils.getFirstWorkDayOfWeek(DateUtils.getLastNDay(periodBeginDate, -7));
    		
    	}
    	
//    	for(PeriodEntity e: periodList){
//    		System.out.println(e.getBeginDate()+"-"+e.getEndDate());
//    	}
    	return periodList;
    }
    
    
    
    
    *//**
     * 根据周期类型（周）和时间范围取得所在范围的 统计周期列表 (  因为水和电是周五统计)
     * @param period
     * @param beginDate
     * @param endDate
     * @return
     *//*
    public static List<PeriodEntity> getWeekPeriodListFriday(String beginDate, String endDate){
    	List<PeriodEntity> periodList = Lists.newArrayList();
    	String periodBeginDate = beginDate;
    	String periodEndDate = "";
    	while (periodBeginDate.compareTo(endDate) <=0){
    		PeriodEntity entity = new PeriodEntity();
    		periodEndDate = getLastFriDayOfWeek(periodBeginDate);
    		if(periodEndDate.compareTo(endDate) >=0){
    			entity.setBeginDate(periodBeginDate);
    			entity.setEndDate(endDate);
    			entity.setName(endDate);
    			periodList.add(entity);
    			break;
    		}else{
    			entity.setBeginDate(periodBeginDate);
    			entity.setEndDate(periodEndDate);
    			entity.setName(periodEndDate);
    		}
    		periodList.add(entity);
    		periodBeginDate = DateUtils.getFirstWorkDayOfWeek(DateUtils.getLastNDay(periodBeginDate, -7));
    		
    	}
    	
//    	for(PeriodEntity e: periodList){
//    		System.out.println(e.getBeginDate()+"-"+e.getEndDate());
//    	}
    	return periodList;
    }
    
    *//**
     * 根据周期类型（月）和时间范围取得所在范围的 统计周期列表
     * @param period
     * @param beginDate
     * @param endDate
     * @return
     *//*
    public static List<PeriodEntity> getMonthPeriodList(String beginDate, String endDate){
    	List<PeriodEntity> periodList = Lists.newArrayList();
    	String periodBeginDate = beginDate;
    	String periodEndDate = "";
    	while (periodBeginDate.compareTo(endDate) <=0){
    		
    		
    		PeriodEntity entity = new PeriodEntity();
    		periodEndDate = getMonthLastWorkDay26(periodBeginDate);
    		if(periodEndDate.compareTo(endDate) >=0){
    			entity.setBeginDate(periodBeginDate);
    			entity.setEndDate(endDate);
    			periodEndDate = endDate;
    			String name = periodEndDate.substring(5, 7);
    			String date = periodEndDate.substring(8, 10);
    			if(date.compareTo("26")>=0){
    				name = (Integer.valueOf(name)+1)+""; 
    			}
    			if("13".equals(name)){
					name = "1";
				}
    			entity.setName(Integer.valueOf(name).toString()+"月");
    			periodList.add(entity);
    			break;
    		}else{
    			entity.setBeginDate(periodBeginDate);
    			entity.setEndDate(periodEndDate);
    			String name = periodEndDate.substring(5, 7);
    			String date = periodEndDate.substring(8, 10);
    			if(date.compareTo("26")>=0){
    				name = (Integer.valueOf(name)+1)+""; 
    				
    			}
    			if("13".equals(name)){
					name = "1";
				}
    			entity.setName(Integer.valueOf(name).toString()+"月");
//    			entity.setName(periodEndDate);
    		}
    		periodList.add(entity);
    		periodBeginDate = DateUtils.getLastNDay(periodEndDate, -1);
    		
    	}
    	
    	for(PeriodEntity e: periodList){
    		System.out.println(e.getBeginDate()+"-"+e.getName());
    	}
    	return periodList;
    }
    */
    
    /**
     * 获取明天的日期
     * @param dateStr
     * @return
     */
    public static String getTomorrow(String dateStr) {
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			Date date = sdf.parse(dateStr);
			Calendar calendar = new GregorianCalendar(); 
	        calendar.setTime(date); 
	        //calendar.add(calendar.YEAR, 1);//把日期往后增加一年.整数往后推,负数往前移动
	        //calendar.add(calendar.DAY_OF_MONTH, 1);//把日期往后增加一个月.整数往后推,负数往前移动
	        calendar.add(calendar.DATE,1);//把日期往后增加一天.整数往后推,负数往前移动 
	        //calendar.add(calendar.WEEK_OF_MONTH, 1);//把日期往后增加一个月.整数往后推,负数往前移动
	        date=calendar.getTime();   //这个时间就是日期往后推一天的结果
	        return sdf.format(date).toString();
		} catch (ParseException e) {
			e.printStackTrace();
		}
       return null;
    }
    
    /**
     * 获取昨天的日期
     * @param dateStr
     * @return
     */
    public static String getYesterday(String dateStr) {
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			Date date = sdf.parse(dateStr);
			Calendar calendar = new GregorianCalendar(); 
	        calendar.setTime(date); 
	        //calendar.add(calendar.YEAR, 1);//把日期往后增加一年.整数往后推,负数往前移动
	        //calendar.add(calendar.DAY_OF_MONTH, 1);//把日期往后增加一个月.整数往后推,负数往前移动
	        calendar.add(calendar.DATE,-1);//把日期往后增加一天.整数往后推,负数往前移动 
	        //calendar.add(calendar.WEEK_OF_MONTH, 1);//把日期往后增加一个月.整数往后推,负数往前移动
	        date=calendar.getTime();   //这个时间就是日期往后推一天的结果
	        return sdf.format(date).toString();
		} catch (ParseException e) {
			e.printStackTrace();
		}
       return null;
    }
    
    /**
     * 获取前两天的日期
     * @param dateStr
     * @return
     */
    public static String getBeforTwoDayDate(String dateStr) {
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			Date date = sdf.parse(dateStr);
			Calendar calendar = new GregorianCalendar(); 
	        calendar.setTime(date); 
	        //calendar.add(calendar.YEAR, 1);//把日期往后增加一年.整数往后推,负数往前移动
	        //calendar.add(calendar.DAY_OF_MONTH, 1);//把日期往后增加一个月.整数往后推,负数往前移动
	        calendar.add(calendar.DATE,-2);//把日期往后增加一天.整数往后推,负数往前移动 
	        //calendar.add(calendar.WEEK_OF_MONTH, 1);//把日期往后增加一个月.整数往后推,负数往前移动
	        date=calendar.getTime();   //这个时间就是日期往后推一天的结果
	        return sdf.format(date).toString();
		} catch (ParseException e) {
			e.printStackTrace();
		}
       return null;
    }
    
    /**
     * 获取昨天的日期
     * @param dateStr
     * @return
     */
    public static String getFifteenDate(String dateStr) {
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			Date date = sdf.parse(dateStr);
			Calendar calendar = new GregorianCalendar(); 
	        calendar.setTime(date); 
	        calendar.add(calendar.DATE,-14);//把日期往后增加一天.整数往后推,负数往前移动 
	        date=calendar.getTime();   //这个时间就是日期往后推一天的结果
	        return sdf.format(date).toString();
		} catch (ParseException e) {
			e.printStackTrace();
		}
       return null;
    }
    
    /**
     * 获取本月的一号日期
     * @return
     */
    public static String initDateByMonth(){
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    	Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date());
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		return sdf.format(calendar.getTime()).toString();
	}
    /**
     * 计算两个字符串日期之间相差的天数
     * @param smdate
     * @param bdate
     * @return
     * @throws ParseException
     */
    public static int daysBetween(String smdate,String bdate){  
    	SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");  
        Calendar cal = Calendar.getInstance(); 
        long time1 = 0;
        long time2 = 0;
        try { 
        	cal.setTime(sdf.parse(smdate));
        	time1 = cal.getTimeInMillis();                 
            cal.setTime(sdf.parse(bdate));    
            time2 = cal.getTimeInMillis();         
		} catch (ParseException e) {
			e.printStackTrace();
		}    
        long between_days=(time2-time1)/(1000*3600*24);  
        return Integer.parseInt(String.valueOf(between_days)) + 1;    
    } 
    
    /**
     * 获取昨天的日期
     * @param dateStr
     * @return
     */
    public static String getAfterDay(String dateStr) {
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			Date date = sdf.parse(dateStr);
			Calendar calendar = new GregorianCalendar(); 
	        calendar.setTime(date); 
	        //calendar.add(calendar.YEAR, 1);//把日期往后增加一年.整数往后推,负数往前移动
	        //calendar.add(calendar.DAY_OF_MONTH, 1);//把日期往后增加一个月.整数往后推,负数往前移动
	        calendar.add(calendar.DATE,2);//把日期往后增加一天.整数往后推,负数往前移动 
	        //calendar.add(calendar.WEEK_OF_MONTH, 1);//把日期往后增加一个月.整数往后推,负数往前移动
	        date=calendar.getTime();   //这个时间就是日期往后推一天的结果
	        return sdf.format(date).toString();
		} catch (ParseException e) {
			e.printStackTrace();
		}
       return null;
    }
    
    /**
     * 获取某个月的最后一个星期天
     * @param dateStr
     * @param day
     * @return
     */
    public static String getSunday(String dateStr, int day){  
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    	Date date = null;
		try {
			date = (new SimpleDateFormat("yyyy-MM")).parse(dateStr);
		} catch (ParseException e) {
			e.printStackTrace();
		}
    	int b = day ;//星期几  的下标 ，假如 星期三 ，下标就是4，星期日的下标是1，  
        //java实现一个月的最后一个星期天  
        Calendar instance = Calendar.getInstance();  
        instance.setTime(date);  
        instance.add(Calendar.MONTH, 1);//月份+1  
        instance.set(Calendar.DAY_OF_MONTH, 1);//天设为一个月的第一天  
        instance.add(Calendar.DAY_OF_MONTH, -1);//本月最后一天  
        int a  = instance.get(Calendar.DAY_OF_WEEK);  
        instance.add(Calendar.DAY_OF_MONTH,  
                b - a > 0?-a-(7-b):b-a);//根据月末最后一天是星期几，向前偏移至最近的周几  
        return sdf.format(instance.getTime()).toString();
    }  
    
    /**
     * 获取某个月的第一个星期一
     * @param
     * @param
     * @return
     */
    public static String firstMonday(String strDate){
    	int year = Integer.parseInt(strDate.substring(0, 4));
    	int month = Integer.parseInt(strDate.substring(5));
    	Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, month - 1); //从0开始
        int day = 1;
        cal.set(Calendar.DAY_OF_MONTH, day);    //从第一天开始找第一个星期一
        while(cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY){
            cal.set(Calendar.DAY_OF_MONTH, ++day);
        }
        Date firstMonday = cal.getTime();
        return new SimpleDateFormat("yyyy-MM-dd").format(firstMonday);
    }

    /**
     * 获取某个月的最后一天的日期  (该方法获取二月四月份最后一天日期有问题。待修改)
     * @param strDate
     * @return
     */
    public static String getLastDayForMonth(String strDate){
    	int year = Integer.parseInt(strDate.substring(0, 4));
    	int month = Integer.parseInt(strDate.substring(5,7));
    	Calendar cal = Calendar.getInstance();
        //设置年份
        cal.set(Calendar.YEAR,year);
        //设置月份
        cal.set(Calendar.MONTH, month-1);
        //获取某月最大天数
        int lastDay = cal.getMaximum(Calendar.DAY_OF_MONTH);
        //设置日历中月份的最大天数
        cal.set(Calendar.DAY_OF_MONTH, lastDay);
        //格式化日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String lastDayOfMonth = sdf.format(cal.getTime());
        return lastDayOfMonth;
    }

    
    /**
     * 获取某个月的第一天的日期
     * @param strDate
     * @return
     */
    public static String getFirstDayForMonth(String strDate){
    	int year = Integer.parseInt(strDate.substring(0, 4));
    	int month = Integer.parseInt(strDate.substring(5,7));
    	Calendar cal = Calendar.getInstance();
        //设置年份
        cal.set(Calendar.YEAR,year);
        //设置月份
        cal.set(Calendar.MONTH, month-1);
        //获取某月最小天数
        int firstDay = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
        //设置日历中月份的最小天数
        cal.set(Calendar.DAY_OF_MONTH, firstDay);
        //格式化日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String firstDayOfMonth = sdf.format(cal.getTime());
        return firstDayOfMonth;
    }
    
    /**
     * 获取某一年的第一天的日期
     * @param strDate
     * @return
     */
    public static String getCurrYearFirst(String strDate){
    	int year = Integer.parseInt(strDate.substring(0, 4));
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    	Calendar calendar = Calendar.getInstance();  
        calendar.clear();  
        calendar.set(Calendar.YEAR, year);  
        return sdf.format(calendar.getTime());  
    }  
    
    /**
     * 获取某一年的最后一天的日期
     * @param strDate
     * @return
     */
    public static String getCurrYearLast(String strDate){
    	int year = Integer.parseInt(strDate.substring(0, 4));
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    	Calendar calendar = Calendar.getInstance();  
        calendar.clear();  
        calendar.set(Calendar.YEAR, year);  
        calendar.roll(Calendar.DAY_OF_YEAR, -1);  
        return sdf.format(calendar.getTime());  
    }


	/**
     * 判断是否为闰年
     * @param strDate
     * @return
     */
    public static boolean leapYear(String strDate) {
    	int year = Integer.parseInt(strDate);
    	if (year%4 == 0 && year%100 != 0 || year%400 == 0) {
    		return true;
    	}
    	return false;
    }
    
    /**
     * 判断当前的某个时间点是否在某个时间段内
     * @param dateStr
     * @return
     */
    public static boolean afterDate(String dateStr) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date date = sdf.parse(sdf.format(new Date()));
			//Date date = sdf.parse("2020-12-28 23:44:00");
			// Date1.after(Date2),当Date2日期比Date1小的时候为true，否则为false;
			// Date1.before(Date2)，当Date1小于Date2时，返回TRUE，当大于等于时，返回false;
			if((sdf.parse(dateStr)).before(date)){ 
	    		return true;
	    	}
		} catch (ParseException e) {
			e.printStackTrace();
		}
    	return false;
    }

	/**
	 * 判断当前的某个时间点是否在某个时间段内
	 * @param dateStr
	 * @return
	 */
	public static boolean beforeDate(String dateStr) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date date = sdf.parse(sdf.format(new Date()));
			//Date date = sdf.parse("2020-12-28 23:44:00");
			// Date1.after(Date2),当Date2日期比Date1小的时候为true，否则为false;
			// Date1.before(Date2)，当Date1小于Date2时，返回TRUE，当大于等于时，返回false;
			if((sdf.parse(dateStr)).after(date)){
				return true;
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return false;
	}
    
    /**
     * 判断当前的某个时间点是否在某个时间段内
     * @param dateStr
     * @return
     */
    public static boolean betweenDate(String firstDate, String endDate, String dateStr) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Date date = sdf.parse(dateStr);
			// Date1.after(Date2),当Date2日期比Date1小的时候为true，否则为false;
			// Date1.before(Date2)，当Date1小于Date2时，返回TRUE，当大于等于时，返回false;
			if((date.before(sdf.parse(endDate)) && 
					date.after(sdf.parse(firstDate)))){ 
	    		return true;
	    	}
		} catch (ParseException e) {
			e.printStackTrace();
		}
    	
    	return false;
    }

	/**
	 * 判断当前的某个时间点是否在某个时间段内
	 * @param dateStr
	 * @return
	 */
	public static boolean betweenDateTime(String firstDate, String endDate, String dateStr) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date date = sdf.parse(dateStr);
			// Date1.after(Date2),当Date2日期比Date1小的时候为true，否则为false;
			// Date1.before(Date2)，当Date1小于Date2时，返回TRUE，当大于等于时，返回false;
			if((date.before(sdf.parse(endDate)) &&
					date.after(sdf.parse(firstDate)))){
				return true;
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}

		return false;
	}
    /**
     * 获取某个日期所在周的周一的日期
     * @param dateStr
     * @return
     */
    public static String getFirstDayOfWeekForDate(String dateStr) {
		try {
	    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 设置时间格式
			Date date = sdf.parse(dateStr);
			Calendar cal = Calendar.getInstance();
			cal.setTime(date);
			// 判断要计算的日期是否是周日，如果是则减一天计算周六的，否则会出问题，计算到下一周去了
			int dayWeek = cal.get(Calendar.DAY_OF_WEEK);// 获得当前日期是一个星期的第几天
			if (1 == dayWeek) {
				cal.add(Calendar.DAY_OF_MONTH, -1);
			}
			cal.setFirstDayOfWeek(Calendar.MONDAY);
			int day = cal.get(Calendar.DAY_OF_WEEK);
			cal.add(Calendar.DATE, cal.getFirstDayOfWeek() - day);
			return sdf.format(cal.getTime());
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
    }
    
    /**
     * 获取某个日期所在周的周天的日期
     * @param dateStr
     * @return
     */
    public static String getLastDayOfWeekForDate(String dateStr) {
		try {
	    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 设置时间格式
			Date date = sdf.parse(dateStr);
			Calendar cal = Calendar.getInstance();
			cal.setTime(date);
			// 判断要计算的日期是否是周日，如果是则减一天计算周六的，否则会出问题，计算到下一周去了
			int dayWeek = cal.get(Calendar.DAY_OF_WEEK);// 获得当前日期是一个星期的第几天
			if (1 == dayWeek) {
				cal.add(Calendar.DAY_OF_MONTH, -1);
			}
			cal.setFirstDayOfWeek(Calendar.MONDAY);
			int day = cal.get(Calendar.DAY_OF_WEEK);
			cal.add(Calendar.DATE, cal.getFirstDayOfWeek() - day);
			cal.add(Calendar.DATE, 6);
	        Date sundayDate = cal.getTime();
			return sdf.format(sundayDate); 
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
    }
    
    /**
     * 比较两个时间的大小
     * @param startDate
     * @param endDate
     * @return
     */
    public static boolean compare(String startDate, String endDate) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			// Date1.after(Date2),当Date2日期比Date1小的时候为true，否则为false;
			// Date1.before(Date2)，当Date1小于Date2时，返回TRUE，当大于等于时，返回false;
			if((sdf.parse(endDate)).before(sdf.parse(startDate))){ 
	    		return true;
	    	}
		} catch (ParseException e) {
			e.printStackTrace();
		}
    	return false;
    }
    
    /**
     * 比较两个月份的大小
     * @param startDate
     * @param endDate
     * @return
     */
    public static boolean compareMonth(String startDate, String endDate) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
			// Date1.after(Date2),当Date2日期比Date1小的时候为true，否则为false;
			// Date1.before(Date2)，当Date1小于Date2时，返回TRUE，当大于等于时，返回false;
			if((sdf.parse(endDate)).before(sdf.parse(startDate))){ 
	    		return true;
	    	}
		} catch (ParseException e) {
			e.printStackTrace();
		}
    	return false;
    }
    
    /**
     * 比较两个时间的大小
     * @param startDate
     * @param endDate
     * @return
     */
    public static boolean compareHourSeconds(String startDate, String endDate) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			// Date1.after(Date2),当Date2日期比Date1小的时候为true，否则为false;
			// Date1.before(Date2)，当Date1小于Date2时，返回TRUE，当大于等于时，返回false;
			if((sdf.parse(endDate)).before(sdf.parse(startDate))){ 
	    		return true;
	    	}
		} catch (ParseException e) {
			e.printStackTrace();
		}
    	return false;
    }
    
    /**
     * 比较两个时间的大小
     * @param startDate
     * @param endDate
     * @return
     */
    public static boolean compareYearMonth(String startDate, String endDate) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
			// Date1.after(Date2),当Date2日期比Date1小的时候为true，否则为false;
			// Date1.before(Date2)，当Date1小于Date2时，返回TRUE，当大于等于时，返回false;
			if((sdf.parse(endDate)).before(sdf.parse(startDate))){ 
	    		return true;
	    	}
		} catch (ParseException e) {
			e.printStackTrace();
		}
    	return false;
    }
    
    /**
     * 比较两个时间的大小
     * @param startDate
     * @param endDate
     * @return
     */
    public static boolean compareYear(String startDate, String endDate) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
			// Date1.after(Date2),当Date2日期比Date1小的时候为true，否则为false;
			// Date1.before(Date2)，当Date1小于Date2时，返回TRUE，当大于等于时，返回false;
			if((sdf.parse(endDate)).before(sdf.parse(startDate))){ 
	    		return true;
	    	}
		} catch (ParseException e) {
			e.printStackTrace();
		}
    	return false;
    }
    /*
    *//**
     * 判断当前的某个时间点是否在某个时间段内
     * @param dateStr
     * @return
     *//*
    public static boolean betweenTwoDateByMinute(String endDate) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date date = sdf.parse(dateStr);
			// Date1.after(Date2),当Date2日期比Date1小的时候为true，否则为false;
			// Date1.before(Date2)，当Date1小于Date2时，返回TRUE，当大于等于时，返回false;
			if((sdf.parse(firstDate)).before(sdf.parse(endDate))){ 
	    		return true;
	    	}
		} catch (ParseException e) {
			e.printStackTrace();
		}
    	return false;
    }*/
    /**
     * 判断当前的某个时间点是否在某个时间段内
     * @param dateStr
     * @return
     */
    public static boolean betweenDateByMinute(String firstDate, String endDate, String dateStr) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date date = sdf.parse(dateStr);
			// Date1.after(Date2),当Date2日期比Date1小的时候为true，否则为false;
			// Date1.before(Date2)，当Date1小于Date2时，返回TRUE，当大于等于时，返回false;
			if((date.before(sdf.parse(endDate)) && 
					date.after(sdf.parse(firstDate)))){ 
	    		return true;
	    	}
		} catch (ParseException e) {
			e.printStackTrace();
		}
    	
    	return false;
    }
    /**
     * 判断当前的某个时间点是否在某个时间段内
     * @param dateStr
     * @return
     */
    public static boolean betweenDateByDay(String firstDate, String endDate, String dateStr) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Date date = sdf.parse(dateStr);
			// Date1.after(Date2),当Date2日期比Date1小的时候为true，否则为false;
			// Date1.before(Date2)，当Date1小于Date2时，返回TRUE，当大于等于时，返回false;
			if((date.before(sdf.parse(endDate)) && 
					date.after(sdf.parse(firstDate)))){ 
	    		return true;
	    	}
		} catch (ParseException e) {
			e.printStackTrace();
		}
    	return false;
    }
    
    /**
     * 判断当前的某个时间点是否在某个时间段内
     * @param dateStr
     * @return
     */
    public static boolean betweenDateByMonth(String firstDate, String endDate, String dateStr) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
			Date date = sdf.parse(dateStr);
			// Date1.after(Date2),当Date2日期比Date1小的时候为true，否则为false;
			// Date1.before(Date2)，当Date1小于Date2时，返回TRUE，当大于等于时，返回false;
			if((date.before(sdf.parse(endDate)) && 
					date.after(sdf.parse(firstDate)))){ 
	    		return true;
	    	}
		} catch (ParseException e) {
			e.printStackTrace();
		}
    	return false;
    }
    
    /**
     * 获取下一小时的日期
     * @param dateStr
     * @return
     */
    public static String getNextHourDate(String dateStr) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date date = sdf.parse(dateStr);
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			calendar.set(Calendar.HOUR,calendar.get(Calendar.HOUR) + 1);// 让日期加1
			date=calendar.getTime();   //这个时间就是日期往后推一天的结果
		    return sdf.format(date).toString();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		return null;
    }
    
    /**
     * 获取上一个小时的日期
     * @param dateStr
     * @return
     */
    public static String getBackHourDate(String dateStr) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date date = sdf.parse(dateStr);
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			calendar.set(Calendar.HOUR,calendar.get(Calendar.HOUR) - 1);
			date=calendar.getTime();   
		    return sdf.format(date).toString();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		return null;
    }
    
    /**
     * 获取上一秒的日期
     * @param dateStr
     * @return
     */
    public static String getBackSecondDate(String dateStr) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date date = sdf.parse(dateStr);
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			calendar.set(Calendar.SECOND,calendar.get(Calendar.SECOND) - 1);
			date=calendar.getTime();   
		    return sdf.format(date).toString();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		return null;
    }
    
    /**
     * 获取上四个小时的日期
     * @param dateStr
     * @return
     */
    public static String getBackFourHourDate(String dateStr) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date date = sdf.parse(dateStr);
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			calendar.set(Calendar.HOUR,calendar.get(Calendar.HOUR) - 4);
			date=calendar.getTime();   
		    return sdf.format(date).toString();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
    }
    
    /**
     * 获取上23个小时的日期
     * @param dateStr
     * @return
     */
    public static String getBackTwentyFourHourDate(String dateStr) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date date = sdf.parse(dateStr);
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			calendar.set(Calendar.HOUR,calendar.get(Calendar.HOUR) - 23);
			date=calendar.getTime();   
		    return sdf.format(date).toString();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
    }
    
    /**
     * 获取上11个小时的日期
     * @param dateStr
     * @return
     */
    public static String getBackTwelveHourDate(String dateStr) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date date = sdf.parse(dateStr);
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			calendar.set(Calendar.HOUR,calendar.get(Calendar.HOUR) - 11);
			date=calendar.getTime();   
		    return sdf.format(date).toString();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
    }
    
    /**
     * 获取上110分钟的日期
     * @param dateStr
     * @return
     */
    public static String getBackOneHundredTenMinDate(String dateStr) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date date = sdf.parse(dateStr);
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			calendar.set(Calendar.MINUTE,calendar.get(Calendar.MINUTE) - 110);
			date=calendar.getTime();   
		    return sdf.format(date).toString();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
    }
	/**
	 * 获取上11个小时的日期
	 * @param dateStr
	 * @return
	 */
	public static String getBackTwelveHourTime(String dateStr) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
			Date date = sdf.parse(dateStr);
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			calendar.set(Calendar.HOUR,calendar.get(Calendar.HOUR) - 11);
			date=calendar.getTime();
			return sdf.format(date).toString();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}

    
    /**
     * 获取上十分钟的日期
     * @param dateStr
     * @return
     */
    public static String getBackTenMinutesDate(String dateStr) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date date = sdf.parse(dateStr);
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			calendar.set(Calendar.MINUTE,calendar.get(Calendar.MINUTE) - 10);
			date=calendar.getTime();   
		    return sdf.format(date).toString();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
    }
    
    /**
     * 获取上一秒的日期
     * @param dateStr
     * @return
     */
    public static String getBackOneSecondDate(String dateStr) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date date = sdf.parse(dateStr);
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			calendar.set(Calendar.SECOND,calendar.get(Calendar.SECOND) - 1);
			date=calendar.getTime();   
		    return sdf.format(date).toString();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
    }
    
    /**
     * 获取下一秒的日期
     * @param dateStr
     * @return
     */
    public static String getNextOneSecondDate(String dateStr) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date date = sdf.parse(dateStr);
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			calendar.set(Calendar.SECOND,calendar.get(Calendar.SECOND) + 1);
			date=calendar.getTime();   
		    return sdf.format(date).toString();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
    }
    
    /**
     * 获取上12秒的日期
     * @param dateStr
     * @return
     */
    public static String getBackTwelveSecondDate(String dateStr) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date date = sdf.parse(dateStr);
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			calendar.set(Calendar.SECOND,calendar.get(Calendar.SECOND) - 12);
			date=calendar.getTime();   
		    return sdf.format(date).toString();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
    }
    
    /**
     * 获取上120秒的日期
     * @param dateStr
     * @return
     */
    public static String getBackTwoMinDate(String dateStr) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date date = sdf.parse(dateStr);
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			calendar.set(Calendar.MINUTE,calendar.get(Calendar.MINUTE) - 2);
			date=calendar.getTime();   
		    return sdf.format(date).toString();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
    }
    
    /**
     * 获取上11秒的日期
     * @param dateStr
     * @return
     */
    public static String getBackElevenSecondDate(String dateStr) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date date = sdf.parse(dateStr);
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			calendar.set(Calendar.SECOND,calendar.get(Calendar.SECOND) - 11);
			date=calendar.getTime();   
		    return sdf.format(date).toString();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
    }
    
    /**
     * 获取下10秒的日期
     * @param dateStr
     * @return
     */
    public static String getNextTenSecondDate(String dateStr) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date date = sdf.parse(dateStr);
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			calendar.set(Calendar.SECOND,calendar.get(Calendar.SECOND) + 10);
			date=calendar.getTime();   
		    return sdf.format(date).toString();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
    }
    
    /**
     * 获取下一个十分钟的日期时间
     * @param dateStr
     * @return
     */
    public static String getNextTenMinuteTime(String dateStr) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date date = sdf.parse(dateStr);
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			calendar.set(Calendar.MINUTE,calendar.get(Calendar.MINUTE) + 10);// 让分钟加10
			date=calendar.getTime();   //这个时间就是日期往后推一天的结果
		    return sdf.format(date).toString();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		return null;
    }
    
    /**
     * 获取上个月的第一天的日期
     * @return
     */
    public static String getLastMonthFirstDayDate() {
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    	Calendar calendar1 = Calendar.getInstance();
        calendar1.add(Calendar.MONTH, -1);
        calendar1.set(Calendar.DAY_OF_MONTH,1);
        String firstDay = sdf.format(calendar1.getTime());
    	return firstDay;
    }
    /**
     * 获取上个月的最后一天的日期
     * @return
     */
    public static String getLastMonthLastDayDate() {
    	 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 
    	 Calendar calendar2 = Calendar.getInstance();
         calendar2.set(Calendar.DAY_OF_MONTH, 0);
         String lastDay = sdf.format(calendar2.getTime());
         return lastDay;
    }
    
    /**
     * 判断两个日期是否在同一个月
     * @param startDate
     * @param endDate
     * @return
     */
    public static boolean judgeMonthSame(String startDate, String endDate) {
    	int startMonth = Integer.parseInt(startDate.substring(5, 7));
    	int endMonth = Integer.parseInt(endDate.substring(5, 7));
    	if (startMonth == endMonth) {
    		return true;
    	}
    	return false;
    }
    
    /**
     * 判断两个日期是否在同一年
     * @param startDate
     * @param endDate
     * @return
     */
    public static boolean judgeYearSame(String startDate, String endDate) {
    	int startYear = Integer.parseInt(startDate.substring(0, 4));
    	int endYear = Integer.parseInt(endDate.substring(0, 4));
    	if (startYear == endYear) {
    		return true;
    	}
    	return false;
    }
    
    /**
     * 获取上个月的26号的日期
     * @return
     */
    public static String getLastMonthTwentySixDayDate(String dateStr) {
    	try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM");
			Date date = sdf1.parse(dateStr);
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
	        calendar.add(Calendar.MONTH, -1);
	        calendar.set(Calendar.DAY_OF_MONTH,26);
	        String firstDay = sdf.format(calendar.getTime());
	    	return firstDay;
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
    }
    
    /**
     * 获取该月的25号的日期
     * @return
     */
    public static String getCurrMonthTwentyFiveDayDate(String dateStr) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM");
			Date date = sdf1.parse(dateStr);
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
	        calendar.add(Calendar.MONTH, 0);
	        calendar.set(Calendar.DAY_OF_MONTH,25);
	        String firstDay = sdf.format(calendar.getTime());
	    	return firstDay;
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
    }
    
    /**
     * 获取该月的26号的日期
     * @return
     */
    public static String getCurrMonthTwentySixDayDate(String dateStr) {
    	try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM");
			Date date = sdf1.parse(dateStr);
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
	        calendar.add(Calendar.MONTH, 0);
	        calendar.set(Calendar.DAY_OF_MONTH,26);
	        String firstDay = sdf.format(calendar.getTime());
	    	return firstDay;
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
    }
    
    /**
     * 将yyyy-MM-dd HH:mm:ss的日期格式转换为y年M月d日 h时m分s秒
     * @param dateStr
     * @return
     */
    public static String dateFormat(String dateStr){
    	try {
    		SimpleDateFormat sdf = new SimpleDateFormat("y年M月d日  h时m分s秒");
    		SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
    		Date date = sdf1.parse(dateStr);
    		return sdf.format(date).toString();
		} catch (ParseException e) {
			e.printStackTrace();
		}
    	return null;
    }
    
    /**
     * 将yyyy-MM-dd的日期格式转换为yyyy/MM/dd
     * @param dateStr
     * @return
     */
    public static String conversionDateFormat(String dateStr){
    	try {
    		SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
    		SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
    		Date date = sdf1.parse(dateStr);
    		return sdf.format(date).toString();
		} catch (ParseException e) {
			e.printStackTrace();
		}
    	return null;
    }
    
    /**
     * 获取上个月月份
     * @return
     */
    public static String getLastMonthDate(String strDate) {
    	try {
    		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        	Calendar calendar1 = Calendar.getInstance();
        	Date date = sdf.parse(strDate);
        	calendar1.setTime(date);
            calendar1.add(Calendar.MONTH, -1);
            String lastMonth = sdf.format(calendar1.getTime());
        	return lastMonth;
		} catch (ParseException e) {
			e.printStackTrace();
		}
    	return null;
    }
    
    /**
     * 获取下个月月份
     * @return
     */
    public static String getNextMonthDate(String strDate) {
    	try {
    		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        	Calendar calendar1 = Calendar.getInstance();
        	Date date = sdf.parse(strDate);
        	calendar1.setTime(date);
            calendar1.add(Calendar.MONTH, 1);
            String lastMonth = sdf.format(calendar1.getTime());
        	return lastMonth;
		} catch (ParseException e) {
			e.printStackTrace();
		}
    	return null;
    }
    
    /**
     * 判断某个日期在那个季度
     * @param date
     * @return
     */
    public static String getQuarter(String date){
    	int month = Integer.parseInt(date.substring(5, 7));
    	if (month >= 1 && month <= 3) {
    		return "一季度";
    	} else if (month >= 4 && month <= 6) {
    		return "二季度";
    	} else if (month >= 7 && month <= 9) {
    		return "三季度";
    	} else if (month >= 10 && month <= 12) {
    		return "四季度";
    	}
    	return null;
    }
    
    /**
     * 某个季度有多少天
     * @param quarter
     * @return
     */
    public static int getQuarterDays(String quarter){
    	int days = 0;
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        Date date = new Date();
        String year = sdf.format(date).toString();
    	if ("一季度".equals(quarter)) {
    		days = daysBetween(year + "-01-01", year + "-03-31");
    	} else if ("二季度".equals(quarter)) {
    		days = daysBetween(year + "-04-01", year + "-06-31");
    	} else if ("三季度".equals(quarter)) {
    		days = daysBetween(year + "-07-01", year + "-09-31");
    	} else if ("四季度".equals(quarter)) {
    		days = daysBetween(year + "-10-01", year + "-12-31");
    	}
    	return days;
    }

	/**
	 * 获取某年某个季度的第一天的日期
	 * @param date
	 * @param quarter
	 * @return
	 */
    public static String getStartDateByQuarter(String date, String quarter) {
		String year = date.substring(0, 4);
		String startDate = null;
		if ("一季度".equals(quarter)) {
			startDate = year + "-01-01";
		} else if ("二季度".equals(quarter)) {
			startDate = year + "-04-01";
		} else if ("三季度".equals(quarter)) {
			startDate = year + "-07-01";
		} else if ("四季度".equals(quarter)) {
			startDate = year + "-10-01";
		}
		return startDate;
	}

	/**
	 * 获取某年某个季度的最后一天的日期
	 * @param date
	 * @param quarter
	 * @return
	 */
	public static String getEndDateByQuarter(String date, String quarter) {
		String year = date.substring(0, 4);
		String endDate = null;
		if ("一季度".equals(quarter)) {
			endDate = year + "-03-31";
		} else if ("二季度".equals(quarter)) {
			endDate = year + "-06-31";
		} else if ("三季度".equals(quarter)) {
			endDate = year + "-09-31";
		} else if ("四季度".equals(quarter)) {
			endDate = year + "-12-31";
		}
		return endDate;
	}
    
    /**
     * 获取两个时间段的小时数
     * @param startTime
     * @param endTime
     * @return
     */
    public static int getHours(String startTime, String endTime) {
    	try {
    		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    		Date start = sdf.parse(startTime);
    		Date end = sdf.parse(endTime);
    		long time = end.getTime() - start.getTime();
    		int hour = (int)(time/(60*60*1000));
    		return hour;
		} catch (ParseException e) {
			e.printStackTrace();
		}
    	return 0;
    }
    
    /**
     * 将yyyy-MM-dd HH:mm:ss 的日期格式转换为yyyy/MM/dd HH:mm:ss
     * @param dateStr
     * @return
     */
    public static String conversionDateFormatHour(String dateStr){
    	try {
    		SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    		SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    		Date date = sdf1.parse(dateStr);
    		return sdf.format(date).toString();
		} catch (ParseException e) {
			e.printStackTrace();
		}
    	return null;
    }
    
    /**
     * 获取当前时间的前一个小时的时间
     * @return
     */
    public static String beforeOneHourToNowDate() {
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    	Calendar calendar = Calendar.getInstance();
    	calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - 1);
    	return sdf.format(calendar.getTime()).toString();
    } 
    
    /**
     * 获取当前时间的后一个小时的时间
     * @return
     */
    public static String afterOneHourToNowDate() {
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    	Calendar calendar = Calendar.getInstance();
    	calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) + 1);
    	return sdf.format(calendar.getTime()).toString();
    } 
    
    /**
     * 获取当前时间的前两个小时的时间
     * @return
     */
    public static String beforeOneHourToTwoDate() {
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    	Calendar calendar = Calendar.getInstance();
    	calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - 2);
    	return sdf.format(calendar.getTime()).toString();
    } 
    
    /**
     * 获取当前时间的前三个小时的时间
     * @return
     */
    public static String beforeOneHourToThreeDate() {
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    	Calendar calendar = Calendar.getInstance();
    	calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - 3);
    	return sdf.format(calendar.getTime()).toString();
    } 
    
    /**
     * 判断某个日期是星期几
     * @param str
     * @return
     */
    public static String judgeWeek(String str) {
    	try {
    		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        	Calendar c = Calendar.getInstance();
    		c.setTime(sdf.parse(str));
    		int dayForWeek = 0;
    		if (c.get(Calendar.DAY_OF_WEEK) == 1) {
    			dayForWeek = 7;
    		} else {
    			dayForWeek = c.get(Calendar.DAY_OF_WEEK) - 1;
    		}
    		if (dayForWeek == 1) {
    			return "星期一";
    		} else if (dayForWeek == 2) {
    			return "星期二";
    		} else if (dayForWeek == 3) {
    			return "星期三";
    		} else if (dayForWeek == 4) {
    			return "星期四";
    		} else if (dayForWeek == 5) {
    			return "星期五";
    		} else if (dayForWeek == 6) {
    			return "星期六";
    		} else if (dayForWeek == 7) {
    			return "星期日";
    		}
		} catch (ParseException e) {
			e.printStackTrace();
		}
    	return null;
    }
    
    /**
     * 判段是白班还是夜班，true为白班，false为夜班
     * @param time1
     * @param time2
     * @return
     */
    public static boolean judgeHoursTime(String time1, String time2) {
    	int hour1 = Integer.parseInt(time1.substring(0, 2));
    	int hour2 = Integer.parseInt(time2.substring(0, 2));
    	boolean flage = false;
    	if ((hour1 != 0 && hour1 != 1 && hour1 != 2 && hour1 != 3 && 
    			hour1 != 4 && hour1 != 5 && hour1 != 6 && hour1 != 7 &&
    			hour1 != 8 && hour1 != 9) && (hour1 <= hour2)) {
    		flage = true;
    	}
    	return flage;
    } 
    
    /**
	 * 获取两个时间点的间隔毫秒数
	 * @param
	 * @return
	 */
	public static long pastMilliseconds(Date startDate, Date endDate) {
		long t = endDate.getTime()-startDate.getTime();
		return t;
	}
	
	/**
	 * 获取某个月份的天数
	 * @param month 月份
	 * @return 天数
	 */
	public static int getDaysOfMonth(String month) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
			Calendar c = Calendar.getInstance();
			c.setTime(sdf.parse(month));
			return c.getActualMaximum(Calendar.DAY_OF_MONTH);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return 30;
	}

	/**
	 * 获取 获取某年某月 所有日期（yyyy-mm-dd格式字符串）
	 * @param year
	 * @param month
	 * @return
	 */
	public static List<String> getMonthFullDay(int year, int month){
		SimpleDateFormat dateFormatYYYYMMDD = new SimpleDateFormat("yyyy-MM-dd");
		List<String> fullDayList = new ArrayList<>(32);
		// 获得当前日期对象
		Calendar cal = Calendar.getInstance();
		cal.clear();// 清除信息
		cal.set(Calendar.YEAR, year);
		// 1月从0开始
		cal.set(Calendar.MONTH, month-1 );
		// 当月1号
		cal.set(Calendar.DAY_OF_MONTH,1);
		int count = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
		for (int j = 1; j <= count ; j++) {
			fullDayList.add(dateFormatYYYYMMDD.format(cal.getTime()));
			cal.add(Calendar.DAY_OF_MONTH,1);
		}
		return fullDayList;
	}

	/**
	 * 获取当前时间的前6个小时的时间
	 *
	 * @return
	 */
	public static String beforeSixHourToNowDate() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - 6);
		return sdf.format(calendar.getTime()).toString();
	}

	/**
	 * 获取某几天前的日期
	 * @param dateTime
	 * @return
	 */
	public static String getDateForDay(String dateTime, Integer num) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date date = sdf.parse(dateTime);
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			calendar.set(Calendar.DATE,calendar.get(Calendar.DATE) - num);
			date=calendar.getTime();
			return sdf.format(date).toString();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * 获取一段时间前或一段时间后日期
	 * @param dateTime 起始日期时间
	 * @param num 一段时间数，一段时间前为num为整负数，一段时间后为整正数
	 * @param type 时间单位
	 * @return 一段时间前或一段时间后日期
	 */
	public static String getDateForSpell(String dateTime, Integer num, String type) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date date = sdf.parse(dateTime);
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			if ("minute".equals(type)) {
				calendar.set(Calendar.MINUTE,calendar.get(Calendar.MINUTE) + num);
			} else if ("hour".equals(type)) {
				calendar.set(Calendar.HOUR_OF_DAY,calendar.get(Calendar.HOUR_OF_DAY) + num);
			} else if ("day".equals(type)) {
				calendar.set(Calendar.DATE,calendar.get(Calendar.DATE) + num);
			} else if ("week".equals(type)) {
				calendar.set(Calendar.WEEK_OF_YEAR,calendar.get(Calendar.WEEK_OF_YEAR) + num);
			} else if ("month".equals(type)) {
				calendar.set(Calendar.MONTH,calendar.get(Calendar.MONTH) + num);
			} else if ("year".equals(type)) {
				calendar.set(Calendar.YEAR,calendar.get(Calendar.YEAR) + num);
			}
			date = calendar.getTime();
			return sdf.format(date);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}

    
}
